<template>
  <div class="main_box" style="padding:10px;">
    <div class="add_wrap">
      <div class="tit">
        <h2>基础信息</h2>
        <el-button plain size="small" type="success" icon="fa fa-mail-forward" @click="returnList"> 返 回</el-button>
      </div>
      <el-form :model="addForm" ref="addForm" label-width="200px" :rules="roleRules">
        <el-row>
          <el-form-item label="上级分类：" prop="parentName" >
            <span>{{addForm.parentName}}</span>
          </el-form-item>
          <el-form-item label="分类名称：" prop="classifyName" >
            <el-input v-model="addForm.classifyName" @keydown.native="keydown($event)"></el-input>
          </el-form-item>
          <el-form-item label="排序：" prop="sort" >
            <el-input v-model="addForm.sort"></el-input>
          </el-form-item>
          <el-form-item label="备注：" prop="remark" >
            <el-input v-model="addForm.remark"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary" @click="sureClick">保 存</el-button>
            <el-button @click="returnList">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
  import * as message from "@/constants/message";
  import AppointItemApi from "@/api/appoint/appointItem";
  export default{
    data(){
      return {
        addForm:{
          parentName:"",
          parentId:"",
          classifyName:"",
          remark:"",
          sort:""
        },
        typeIds:[],
        roleRules: {
          classifyName: [
            { required: true, message: "请输入分类名称", trigger: "blur" }
          ]
        }
      }
    },
    methods: {
      init(){
        this.addForm.parentId = this.$route.query.id;
        this.addForm.parentName = this.$route.query.name;
      },
      keydown(e) {
        if (e.keyCode == 32) {
          e.returnValue = false;
        }
      },
      sureClick() {
        this.$refs.addForm.validate(valid => {
          if (valid) {
            this.addClassify();
          }
        })
      },
      addClassify() {
        let data = {
          parentId: this.addForm.parentId,
          classifyName: this.addForm.classifyName,
          remark: this.addForm.remark,
          sort: this.addForm.sort
        };
        AppointItemApi.addItemClassify(data)
          .then(data => {
            this.$Utils.notifySuccess()
            this.returnList();
          })
      },
      returnList(){
        this.$store.dispatch('delView', this.$route);
        this.$router.push({path: '/appoint/classifyManagement'})
      }
    },

    mounted(){
      this.init();
    }
  }
</script>
<style lang="scss" src="@/assets/css/views/add.scss" scope>
</style>
